package com.bj.disc.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.ai3d.rfid.R
import com.ai3d.rfid.base.activity.BaseContainerVmActivity
import com.ai3d.rfid.base.vm.ContainerViewModel
import com.ai3d.rfid.common.libs.InitLanguage
import com.ai3d.rfid.common.proxy.ToastProxy
import com.ai3d.rfid.databinding.LayoutContainerBinding
import com.bj.disc.fragment.MainFragment
import com.bj.disc.service.MyIntentService

class MainActivity : BaseContainerVmActivity<ContainerViewModel, LayoutContainerBinding>() {
    companion object {
        fun startMainActivity(activity: Activity) {
            var intent = Intent(activity, MainActivity::class.java)
            activity.startActivity(intent)
            activity.finish()
            //activity?.overridePendingTransition(0, 0)
        }
    }

    lateinit var curFragment: MainFragment
    var exitTime = 0L
    override fun initView(savedInstanceState: Bundle?) {
        curFragment = MainFragment()
        changeFragment(curFragment)
        MyIntentService.startMyIntentService(this@MainActivity)
    }

    override fun onBackPressed() {
        loginOut()
    }

    private fun loginOut() {
        if (System.currentTimeMillis() - exitTime > 2000) {
            ToastProxy.showShort(R.string.press_again_to_exit_the_program)
            exitTime = System.currentTimeMillis()
        } else {
            InitLanguage.finishAll()
        }
    }


    override fun onDestroy() {
        super.onDestroy()
    }

//    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
//        // Logcat.d("onKeyDown keyCode : $keyCode")
//        // curFragment.onKeyDown(keyCode, event)
//        return super.onKeyDown(keyCode, event)
//    }


    //    override fun onStop() {
//        super.onStop()
//        ClientManager.stop()
//    }
}